package bs2cirvolas;


import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.MultivariateRealOptimizer;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.RealPointValuePair;
import org.apache.commons.math.optimization.direct.NelderMead;




public class TestMinimizer {

	public TestMinimizer() {
		// TODO Auto-generated constructor stub
	}

//	/**
//	 * @param args
//	 * @throws IllegalArgumentException 
//	 * @throws FunctionEvaluationException 
//	 * @throws OptimizationException 
//	 */
//	public static void main(String[] args) throws OptimizationException, FunctionEvaluationException, IllegalArgumentException {
//		// TODO Auto-generated method stub
//		MultivariateRealFunction testFunction= new TestFunction();
//		double[] init= new double[2];
//		init[0]=-80;
//		init[1]=80;
//	
//		MultivariateRealOptimizer mvopt = new NelderMead(); 
//		//AVAILABLE OPTIMIZERS ARE DirectSearchOptimizer, MultiDirectional, MultiStartMultivariateRealOptimizer, NelderMead
//		//http://commons.apache.org/math/api-2.2/org/apache/commons/math/optimization/MultivariateRealOptimizer.html
// 
//		RealPointValuePair MinPointValuePair=mvopt.optimize(testFunction,GoalType.MINIMIZE,init);
//		double[] MinPoint=MinPointValuePair.getPoint();
//		double MinValue=MinPointValuePair.getValue();
//		System.out.println("Minimum for function testFunction is for point("+MinPoint[0]+" "+MinPoint[1]+"). Value of the function is "+MinValue);
//	}

	
	
	
	/**
	 * @param args
	 * @throws IllegalArgumentException 
	 * @throws FunctionEvaluationException 
	 * @throws OptimizationException 
	 */
	public static void main(String[] args) throws OptimizationException, FunctionEvaluationException, IllegalArgumentException {
		// TODO Auto-generated method stub
		MultivariateRealFunction testFunction= new TestFunction();
		double[] init= new double[2];
		init[0]=-1;
		init[1]=1;
	
		MultivariateRealOptimizer mvopt = new NelderMead(); 
		//AVAILABLE OPTIMIZERS ARE DirectSearchOptimizer, MultiDirectional, MultiStartMultivariateRealOptimizer, NelderMead
		//http://commons.apache.org/math/api-2.2/org/apache/commons/math/optimization/MultivariateRealOptimizer.html
 
		RealPointValuePair MinPointValuePair=mvopt.optimize(testFunction,GoalType.MINIMIZE,init);
		double[] MinPoint=MinPointValuePair.getPoint();
		double MinValue=MinPointValuePair.getValue();
		System.out.println("Minimum for function testFunction is for point("+MinPoint[0]+" "+MinPoint[1]+"). Value of the function is "+MinValue);
	}

}
